package com.ss.android.article.base.feature.feed.presenter;

import android.content.Context;
import android.os.Handler;

import com.bytedance.article.common.c.TTUtils;
import com.ss.android.account.Spipe;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.UrlBuilder;

public final class ArticleActionThread extends AbsApiThread {
    private final Action a;
    private final Handler mHandler;
    private final Context mContext;
    private int d;

    public ArticleActionThread(Context context, Handler handler, int arg10, long arg11, Article arg13, long arg14) {
        super("ArticleActionThread");
        this.d = 1;
        this.mContext = context.getApplicationContext();
        this.mHandler = handler;
        this.a = new Action(arg10, arg11, arg13, arg14);
        this.d = 2;
    }

    private static boolean doAction(Action arg8, Context context, int arg10) {
        boolean v0 = false;
        int v3 = 0;
        label_3:
        while (v3 < arg10) {
            try {
                if (android.support.design.a.isTextEmpty(arg8.action)) {
                    return v0;
                }
                UrlBuilder urlBuilder = new UrlBuilder();
                urlBuilder.addParam("action", arg8.action);
                if (arg8.article != null) {
                    urlBuilder.addParam("group_id", arg8.article.groupId);
                    urlBuilder.addParam("item_id", arg8.article.itemId);
                    urlBuilder.addParam("aggr_type", arg8.article.aggrType);
                }

                if (arg8.ad_id > 0) {
                    urlBuilder.addParam("ad_id", arg8.ad_id);
                }

                urlBuilder.addParam("item_version", arg8.d);
                urlBuilder.addParam("subject_group_id", arg8.e);
                String responseString = NetworkUtils.executePost(
                        20480,
                        ArticleConstants.articleItemActionUrl,
                        urlBuilder.mList);
                if (responseString == null) {
                    return v0;
                }

                if (responseString.length() == 0) {
                    return v0;
                }
                return true;
            } catch (Throwable throwable) {
                int errorCode = TTUtils.getErrorCode(context, throwable);
                if (errorCode == 13 || errorCode == 14) {
                    errorCode = 1;
                } else {
                    errorCode = 0;
                }
                if ((errorCode > 0)) {
                    ++v3;
                    continue;
                } else {
                    return v0;
                }
            }
        }
        return v0;


    }

    public final void run() {
        int v0 = doAction(this.a, this.mContext, this.d) ? 1005 : 1006;
        if (this.mHandler != null) {
            this.mHandler.sendMessage(this.mHandler.obtainMessage(v0, this.a));
        }
    }

    public final class Action {
        public int a;
        public String action;
        public long c;
        public long d;
        public long e;
        public long ad_id;
        public Article article;

        public Action(int arg3, long arg4, Article arg6, long arg7) {
            this.a = arg3;
            this.action = Spipe.a(arg3);
            this.c = arg4;
            this.d = arg6.itemVersion;
            this.e = arg6.subjectGroupId;
            this.ad_id = arg7;
            this.article = arg6;
        }
    }
}

